import datetime
import time
dictread01={}
dictwr01={}
dictread01delta={}
dictwr01delta={}
import json
import urllib.request
def get_data(url):
    htmlfile = urllib.request.urlopen(url)
    htmltext = htmlfile.read().decode('utf-8')
    m2= json.loads(htmltext)

    for i in m2['beans']:
        if 'Regions' in i['name']:
            #print (i['name'])
            for j in i.keys():
                if 'readReque' in j:
                    tname=(str(j).replace('Namespace_default_table_',''))
                    #print(tname)
                    v2=int(i[j])
                    #print (v2)
                    try :
                        old=dictread01[tname]
                    except:
                        old=0
                    dictread01[tname]=v2
                    dictread01delta[tname]=v2-old

            for j in i.keys():
                if 'writeReque' in j:
                    tname = (str(j).replace('Namespace_default_table_', ''))
                    #print(tname)
                    v2 = int(i[j])
                    #print(v2)
                    try :
                        old=dictwr01[tname]
                    except:
                        old=0
                    dictwr01[tname]=v2
                    dictwr01delta[tname]=v2-old
        #print (i)
#print (m2)

#print(htmltext)
while 1:

    get_data('http://VECS01937:16030/jmx')
    #print (dictread01delta)
    print ('++++++++++++++++++++++++++++++++++++++++++++++++++')
    print ('++++++++++++++++++++++++++++++++++++++++++++++++++')
    print ('VECS01130')
    print (datetime.datetime.now())
    print ('++++++++++++++++++++++++++++++++++++++++++++++++++')
    print ('++++++++++++++++++++++++++++++++++++++++++++++++++')
    print('read table------------------------------------')
    #print(sorted(dictread01delta.items(), key=lambda k: (k[1], k[0]), reverse=True))
    listdis1=sorted(dictread01delta.items(), key=lambda k: (k[1], k[0]), reverse=True)
    for m1 in listdis1[:11]:
        print (m1)
    #print (listdis1[:5])
    print ('\n')
    #print (dictwr01delta)
    print('write table------------------------------------')
    #print(sorted(dictwr01delta.items(), key=lambda k: (k[1], k[0]), reverse=True))
    listdis2=sorted(dictwr01delta.items(), key=lambda k: (k[1], k[0]), reverse=True)
    for m2 in listdis2[:11]:
        print (m2)
    #print (listdis2[:5])
    print('\n')
    dictread01delta={}
    dictwr01delta={}
    time.sleep(10)